import store from "@/store";
import {
	computed
} from "vue";
import useLoginTodo from "@/composition/useLoginTodo.js";

export default function useGetFollowArticle(data) {
	const {
		$http,
	} = data;
	const userInfo = computed(() => {
		return store.state.userInfo;
	});

	const getFollowArticle = async (isLoading) => {
		try {
			// 检查用户是否登录
			const {
				checkedisLogin
			} = useLoginTodo(userInfo);
			const isLogin = await checkedisLogin();
			if (!isLogin) {
				return {
					list: []
				};
			}

			// 检查用户ID是否存在
			if (!userInfo.value || !userInfo.value._id) {
				console.error("用户ID不存在");
				return {
					list: []
				};
			}

			const res = await $http.get_follow_article({
				userId: userInfo.value._id,
				isLoading
			});
			return res || {
				list: []
			};
		} catch (error) {
			console.error("获取关注文章失败", error);
			return {
				list: []
			};
		}
	};

	return {
		getFollowArticle,
	};
}